package com.nintendo.bubblechat.controller;

import com.nintendo.bubblechat.config.MinioConfig;
import com.nintendo.bubblechat.grace.result.GraceJsonRequest;
import com.nintendo.bubblechat.utils.MinioUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping("/minio")
@CrossOrigin
public class MinioController {
    @Autowired
    private MinioConfig minioConfig;
    @Autowired
    private MinioUtils minioUtils;
    @PostMapping("/upload")
    public GraceJsonRequest upload(@RequestParam("file") MultipartFile file){
        String url = null;
        try {
            url = minioUtils.upload(file);
        } catch (Exception e) {
            e.printStackTrace();
        }
        url = "http://"+minioConfig.getEndpoint()+":"+minioConfig.getPort()+"/"+url;
        System.out.println(url);
        return GraceJsonRequest.ok(url);
    }
}
